/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package as24gc.common;

import java.io.File;

/**
 *
 * @author nico.vassallo
 */
public class DeleteFolder {

    private static void DelDir(String dir) {
        boolean success = (new File(dir)).delete();
        if (success) {
            System.out.println("delete folder with success: " + dir);
        } else {
            System.out.println("Error during delete folder: " + dir);
        }
    }

    private static boolean DelDirSubFolder(File dir) {
        if (dir.isDirectory()) {
            String[] contenuto = dir.list();
            for (int i = 0; i < contenuto.length; i++) {
                System.out.println("delete "+contenuto[i]);
                boolean success = DelDirSubFolder(new File(dir, contenuto[i]));
                if (!success) {
                    return false;
                }
            }
        }
        return dir.delete();
    }

    public static boolean runDeleteFolder(String dir) {
        DelDir(dir);
        boolean success = DelDirSubFolder(new File(dir));
        System.out.println("delete folder: " + dir + " - " + success);
        return success;

    }
}
